import { defHttp } from '/@/utils/http/axios';

enum userCenter {
  // 设置用户信息
  setUserInfo = 'uc/setUserInfo',
  // 设置密码
  setPassword = 'uc/setPassword',
  // 获取用户的权限
  getUserAuth = 'system/getUserAuth',
}

enum system {
  // 获取用户配置信息，包含组，权限，主题信息
  getUserSetting = 'system/getUserSetting',
  // 设置用户角色
  setUserRole = 'system/setUserRole',
  // 给用户分配权限
  setUserAuth = 'system/setUserAuth',
  // 删除用户角色
  removeUserAuth = 'system/removeUserAuth',
  // 给角色分配权限
  setRoleAuth = 'system/setRoleAuth'
}
const HttpApi = {
  setUserInfo(params) {
    return defHttp.post({
      url: '/admin/' + userCenter.setUserInfo,
      params: params
    },
    {
      errorMessageMode: 'normal',
    });
  },
  setPassword(params) {
    return defHttp.post({
      url: '/admin/' + userCenter.setPassword,
      params: params
    },
    {
      errorMessageMode: 'normal',
    });
  },
  getUserAuth() {
    return defHttp.get({
      url: '/admin/' + userCenter.getUserAuth,
      params: {}
    });
  },
  getUserSetting(user_id: Number) {
    return defHttp.post({
      url: '/admin/' + system.getUserSetting,
      params: {
        user_id: user_id
      }
    });
  },
  setUserRole(user_id: Number, role_id: Array) {
    return defHttp.post({
      url: '/admin/' + system.setUserRole,
      params: {
        user_id: user_id,
        role_id: role_id
      }
    });
  },
  setUserAuth(user_id: Array, auth_id: Array) {
    return defHttp.post({
      url: '/admin/' + system.setUserAuth,
      params: {
        user_id: user_id,
        auth_id: auth_id
      }
    });
  },
  removeUserAuth(user_id: Array, paths: Array) {
    return defHttp.post({
      url: '/admin/' + system.removeUserAuth,
      params: {
        user_id: user_id,
        paths: paths
      }
    });
  },
  setRoleAuth(role_id: Array, auth_id: Array) {
    return defHttp.post({
      url: '/admin/' + system.setRoleAuth,
      params: {
        role_id: role_id,
        auth_id: auth_id
      }
    });
  }
};

export default HttpApi;
